-- Rebels
-- Created by cheny3 Sep/09/2016
-- 受伤的反叛军

-- 初始化
function initRebels(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            local pos = self.gridData:getPos();
            local grid = DungeonM.getGridByPos(pos);
            local classId = grid.class_id;

            -- 还未提交
            local function okFunc(classId)
                -- 执行提交/关闭界面
                DungeonActionM.go("rebels_submit", self.gridData:getPos(), classId);
                UIMgr.getCurrentScene():removeFormByName("UIBuildingSubmit");
                playBuildingStrongLight(self);

                local msg = FormulaM.invoke("CALC_REBELS_BONUS_DESC", ME.user, classId);
                local list = splitString(msg, "\n");
                splitAlert(list);
            end

            -- 打开建筑提交界面
            self:openBuildingSubmit(okFunc, EQUIP_OPEN_TYPE_HELMET);
        end
    end

    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
end
